package main.java.br.com.projeto.domain.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import main.java.br.com.projeto.domain.entity.Grupo;

public class DaoGrupo extends Dao<Grupo> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6276568541792867922L;

	public DaoGrupo() {
		super(Grupo.class);
	}
	
	public List<Grupo> listByFilter(Long id, String filter) {
		String hql = "select grupo from Grupo grupo "
				+ "where (lower(grupo.grupo) like '%' || lower ( cast(:filter as string) ) || '%' or :filter = null) "
				+ "and (grupo.id = :id or :id = 0)";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("filter", filter);
		parameters.put("id", id);

		return this.findOneResult(hql, parameters);
	}
	
	public List<Grupo> listGrupoByQuery( String query )
	{
		String hql = "select grupo from Grupo grupo "
				+ "where (lower(grupo.grupo) like '%' || lower ( cast(:query as string) ) || '%') ";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("query", query);

		return this.findOneResult(hql, parameters);
	}
}
